package com.newaim.controller;


import com.newaim.common.pojo.CommonResult;
import com.newaim.common.util.object.BeanUtils;
import com.newaim.entity.ProductRrpDO;
import com.newaim.service.ProductRrpService;
import com.newaim.vo.ProductRrpVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.newaim.common.pojo.CommonResult.success;


/**
 * 获取sku对应的RRP
 * @author heath.zhong
 */
@Tag(name = "RRP-API")
@RestController
@RequestMapping("/system/oauth2/rrp")
@Validated
@Slf4j
public class ProductRrpController {

    @Resource
    private ProductRrpService productRrpService;


    @GetMapping("/getByListingSKU")
    @Operation(summary = "根据listing sku获得RRP")
    @PreAuthorize("@ss.hasScope('product.read')") //
    public CommonResult<ProductRrpVO> getByListingSKU(String sku) {
        // 获得用户基本信息
        ProductRrpDO user = productRrpService.selectBySku(sku);
        ProductRrpVO resp = BeanUtils.toBean(user, ProductRrpVO.class);
        return success(resp);
    }

}
